<#include "/common/head.ftl">

<@showTitle title="${i18n.getMessage('receipt')} > ${i18n.getMessage('edit')}">
	<a href="#" onclick="cc('receipt/showInfoOfferingReceipt.sgt?id=${receipt.id}')">${i18n.getMessage('receipt')}</a>
</@showTitle>

<div id="error" style="display:none"></div>

<form action="receipt/editOfferingReceipt.sgt" validator="receipt/validateOfferingReceipt.sgt" onsubmit="submitFormValidation(this); return false" onreset="$('error').hide()">
	<input type="hidden" name="id" value="${(receipt.id)!}"/>
	<input type="hidden" name="offeringId" value="${(receipt.offering.id)!}"/> 
	<table id="dataTable" cellspacing="5" cellpadding="0" align="center">
		<tr>
			<td class="name">${i18n.getMessage('student')}:</td>
			<td>${(receipt.student.fullName)!}</td>
		</tr>
		<tr>
			<td class="name">${i18n.getMessage('level')}:</td>
			<td>
				<select name="levelId" disabled="disabled" id="levelId" class="w300" onchange="requestSelectOption('receipt/requestOfferingByLevelId.sgt', this, 'offeringId')">
					<option></option>
					<#list programs as program>
						${request.setAttribute("levels", program.levels)}
						<optgroup label="${program.name}">
							<#list levels as level>
								<option value="${level.id}" <#if (level = receipt.offering.level)>selected</#if>>${level.name}</option>
							</#list>
						</optgroup>
					</#list>
				</select>
			</td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('offering')}:</td>
			<td><input type="text" readonly="readonly" id="offeringId" class="w200" 
					value="${receipt.offering.startDate?date}-${receipt.offering.endDate?date}#${receipt.offering.name}" />
			</td>
		</tr>
		<tr>
			<td class="name">${i18n.getMessage('number')}:</td>
			<td><input type="text" readonly="readonly" name="number" value="${(receipt.number)!}" class="w200" /></td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('date')}:</td>
			<td><input type="text" readonly="readonly" name="date" value="${(receipt.date?date)!}" class="w200" /></td>
		</tr>
		<tr>
			<td class="name">Discount Items:</td>
			<td>
				<#assign description = "">
				<#list keys as key>
					<#assign items = discountItems(key)>
					<#list items as item>
						<#if item == (receipt.discountItem)!>
							<#assign description = item.getName()>
						</#if>
					</#list>
				</#list>
				<#list amountDiscountItems as item>
					<#if item == (receipt.discountItem)!>
						<#assign description = item.getName()>
					</#if>
				</#list>
				
				<#list keys as key>
					<#assign items = discountItems(key)>
					<#list items as item>
						<#if item == (receipt.discountItem2)!>
							<#assign description = description + ", " + item.getName()>
						</#if>
					</#list>
				</#list>
				<#list amountDiscountItems as item>
					<#if item == (receipt.discountItem2)!>
						<#assign description = description + ", " + item.getName()>
					</#if>
				</#list>
				${description!}
			</td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('fee')}:</td>
			<td><input type="text" readonly="readonly" name="fee" value="${(receipt.fee.amount)!}" style="width:170px"/> ${i18n.getMessage('currency.vnd')}</td>
		</tr>
		<tr>
			<td class="name"><@required/>${i18n.getMessage('cashier')}:</td>
			<td>
				<select name="cashierId" style="width:204px">
					<option></option>
					<optgroup label="Active">
						<#list cashiers as cashier>
							<#if cashier.active>
								<option value="${(cashier.id)!}" <#if cashier == (receipt.cashier)!>selected</#if> style="<@formatOnConsultant cashier/>">${(cashier.lastName)!} ${(cashier.firstName)!}</option>								
							</#if>
						</#list>					
					</optgroup>
					<optgroup label="Inactive">
						<#list cashiers as cashier>
							<#if !cashier.active>
								<option value="${(cashier.id)!}" <#if cashier == (receipt.cashier)!>selected</#if> style="<@formatOnConsultant cashier/>">${(cashier.lastName)!} ${(cashier.firstName)!}</option>								
							</#if>
						</#list>					
					</optgroup>
				</select>
			</td>
		</tr>
		<tr>
			<td class="name" style="vertical-align:top">${i18n.getMessage('comment')}:</td>
			<td><textarea name="comment" style="width:350px;height:80px">${(receipt.comment)!}</textarea></td>
		</tr>
		<tr>
			<td class="name"></td>
			<td>
				<input type="submit" value="${i18n.getMessage('edit')}" class="button_style"/> 
				<input type="reset" value="${i18n.getMessage('reset')}" class="button_style"/>
			</td>
		</tr>
	</table>
</form>